<template>
  <div>
    <!-- 主图下的分类轮播 -->
    <div class="icons">
      <swiper :options="swiperOptions">
        <!-- pages 是切分出来的数组 [[8],[2]]  item代表一个数组中的两个数组 -->
        <swiper-slide v-for="(item,index) in pages" :key="index">
          <!-- 遍历数组中的内容 v内容 index下标  v下找内容 -->
          <div class="icon" v-for="(v,index) in item" :key="index">
            <div class="icon-img">
              <img :src="v.icon" alt width="60%" />
            </div>
            <p class="icon-desc">{{v.context}}</p>
          </div>
        </swiper-slide>
        <div class="swiper-pagination " slot="pagination" style="bottom: 5px"></div>
      </swiper>
    </div>
    <div class="classify_con">
      <div class="classift_con_chi"><span class="iconfont icon_min">&#xe60b;</span>定位失败</div>
      <div class="classift_con_chi two"><span class="iconfont icon_min">&#xe61a;</span>必游榜单</div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      swiperOptions: {
        pagination: ".swiper-pagination", // 轮播图的点
        loop: true, // 循环
      },

      classifyItem: [
        {
          id: 1,
          context: "景点门票",
          icon:
            "https://imgs.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png",
        },
        {
          id: 2,
          context: "一日游",
          icon:
            "https://imgs.qunarzz.com/piao/fusion/1804/5a/13ceb38dcf262f02.png",
        },
        {
          id: 3,
          context: "北京园博园",
          icon:
            "https://imgs.qunarzz.com/piao/fusion/1803/4c/eac47dd8def8de02.png",
        },
        {
          id: 4,
          context: "故宫",
          icon:
            "https://imgs.qunarzz.com/piao/fusion/1803/6c/9e54a8540fee0102.png",
        },
        {
          id: 5,
          context: "中国马镇",
          icon:
            "https://imgs.qunarzz.com/piao/fusion/1803/47/c2b659e048b11602.png",
        },
        {
          id: 6,
          context: "古北水镇",
          icon:
            "https://imgs.qunarzz.com/piao/fusion/1803/67/9a1678221b8e0e02.png",
        },
        {
          id: 7,
          context: "香水公园",
          icon:
            "https://mp-piao-admincp.qunarzz.com/mp_piao_admin_mp_piao_admin/admin/20193/a40ee278d67000f2a29d2e20f6a029b3.png",
        },
        {
          id: 8,
          context: "凤凰岭",
          icon:
            "https://mp-piao-admincp.qunarzz.com/mp_piao_admin_mp_piao_admin/admin/20193/a40ee278d67000f2a29d2e20f6a029b3.png",
        },
        {
          id: 9,
          context: "踏青赏花",
          icon:
            "https://imgs.qunarzz.com/piao/fusion/1803/bd/9f7b9b2b60c1502.png",
        },
        {
          id: 10,
          context: "圆明园",
          icon:
            "https://imgs.qunarzz.com/piao/fusion/1803/6c/9e54a8540fee0102.png",
        },
      ],
    };
  },
  computed: {
    pages() {
      const pages = [];
      this.classifyItem.forEach((item, index) => {
        //page当前下标的数据应该展示在轮播图的第几页   index是3 下标是2  Math.floor(2/8)向下取整为0  Math.floor(8/8)向下取整为1
        const page = Math.floor(index / 8);
        if (!pages[page]) {
          pages[page] = [];
        }
        pages[page].push(item);
      });
      return pages;
    },
  },
};
</script>

<style lang="stylus" scoped>
@import '~@/assets/styles/varibles.styl';
.icons >>> .swiper-container {
  height: 0;
  padding-bottom: 47%;
}

.icon {
  position: relative;
  overflow: hidden;
  float: left;
  width: 25%;
  height: 0;
  padding-bottom: 20%;

  // background : red
  .icon-img {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0.44rem;
    // background :blue
    box-sizing: border-box;
    padding: 0.05rem;
    text-align: center;

    .icon-img-content {
      display: block;
      margin: 0 auto;
      height: 100%;
    }
  }

  .icon-desc {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 0.44rem;
    line-height: 0.44rem;
    text-align: center;
    color: #333;
  }
}
.classify_con 
  width 100%
  height 0.98rem
  border-top 0.01rem solid #cdcdcd
  display flex
  .classift_con_chi
    width 50%
    height 0.98rem
    text-align center
    line-height 0.98rem
  .two
    border-left 0.01rem solid #cdcdcd
  
</style>